package com.token.controller;

import com.token.annotation.DecryptMethod;
import com.token.annotation.EncryptMethod;
import com.token.common.ResultMessage;
import com.token.model.dto.User;
import com.token.model.dto.UsersDTO;
import com.token.service.TestUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @auther: henriy
 * @Date: 2023/11/29
 */
@RestController
@RequestMapping("/desensitization")
public class DesensitizationController {

    @Resource
    private TestUserService testUserService;

    /**
     * 创建用户对象 模拟从数据库中取值
     */
    private User createUser() {
        return new User(110L, "admin", "18326313814", "136148@qq.com");
    }

    /**
     * 脱敏数据
     */
    @GetMapping("/test1")
    public ResultMessage test1() {
        User user = createUser();
        return ResultMessage.isOk(user);
    }

    @EncryptMethod
    @PostMapping("/addUser")
    public ResultMessage addUser(@RequestBody UsersDTO usersDTO) {
        testUserService.addUser(usersDTO);
        return ResultMessage.isOk();
    }

    @DecryptMethod
    @GetMapping("/selectUser")
    public ResultMessage selectUser(@RequestParam(value = "id") Long id) {
        return ResultMessage.isOk(testUserService.selectUser(id));
    }

    @GetMapping("/selectDecrypt")
    public ResultMessage selectDecrypt(@RequestParam(value = "address") String address) {
        return ResultMessage.isOk(testUserService.selectDecrypt(address));
    }

}
